package com.zwy.ubts.config;

import com.yg.yws.Info;
import com.yg.yws.annotation.YWebPackage;
import com.yg.yws.filter.YWebFilter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * @Author zwy
 * @Description:写过滤器可以不用配置web.xml，因为有注解标志过滤器@WebFilter
 * @Date Created in 12:46 2022/12/23
 */
@WebFilter("/*")
@YWebPackage("com.zwy.ubts.controller")
public class ZFilter extends YWebFilter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        super.init(filterConfig);
        //显示框架YWebServlet的日志
        Info.isShowMsg = true;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) {
        super.doFilter(servletRequest, servletResponse, filterChain);
    }

    @Override
    public void destroy() {
        super.destroy();
    }

    @Override
    public void doFunctionPre(HttpServletRequest req, HttpServletResponse resp) {
        //防止中文乱码
        try {
            req.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    }
}
